package com.cavy.platform.server.domain;

import com.cavy.platform.server.BeansProvider;
import com.cavy.platform.server.repository.ConfigMapRepository;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;

@Data
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = StringConfigMap.class)
@JsonSubTypes({
        @JsonSubTypes.Type(value = StringConfigMap.class),
        @JsonSubTypes.Type(value = FileConfigMap.class)})
public abstract class AbstractConfigMap implements ConfigMap {
    protected String name;
    protected String workSpace;
    protected ConfigMapType type;

    public void save() {
        repository().save(this);
    }

    protected ConfigMapRepository repository() {
        return BeansProvider.getBean(ConfigMapRepository.class);
    }

    public void delete() {
        repository().delete(this);
    }
}
